package com.yx.cloud.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.GridLayoutManager;

import com.iot.base.bean.Product;
import com.iot.base.service.IOTProductManager;
import com.yx.cloud.Interface.OnItemClickListener;
import com.yx.cloud.MyApplication;
import com.yx.cloud.R;
import com.yx.cloud.adapter.HelpSelectSeriesAdapter;
import com.yx.cloud.base.BaseActivity;
import com.yx.cloud.databinding.HelpandfeedbackActivityBinding;
import com.yx.cloud.utils.Intent_utils;
import com.yx.cloud.utils.RomUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 帮助与反馈界面
 */
public class HelpAndFeedbackActivity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "HelpAndFeedbackActivity";
    private Dialog dialog;
    private List<Product> SelectSeriesList;
    private HelpandfeedbackActivityBinding binding;
    private MyApplication application;

    @Override
    public void onCreate() {
        binding = HelpandfeedbackActivityBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        application = (MyApplication) this.getApplicationContext();
        initData();

    }

    private void initData() {
        //选择机器型号
        SelectSeriesList = new ArrayList();

        Product product = new Product();
        product.setProductId("123456789");
        product.setProductName("APP");
        product.setProductIcon(R.mipmap.help_app_icon);
        SelectSeriesList.add(product);
        List<Product> deviceMap= IOTProductManager.getProductList();
        SelectSeriesList.addAll(deviceMap);

        HelpSelectSeriesAdapter selectSeriesAdapter = new HelpSelectSeriesAdapter(this, SelectSeriesList);
        GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
        binding.rvHelpSelectSeries.setLayoutManager(layoutManager);
        binding.rvHelpSelectSeries.setAdapter(selectSeriesAdapter);

        selectSeriesAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent selectseries = new Intent(HelpAndFeedbackActivity.this, HelpFeedbackMessageActivity.class);
                selectseries.putExtra("help", SelectSeriesList.get(position).getProductName());
                startActivity(selectseries);
            }
        });
        binding.ivHelpAndFeedbackReturn.setOnClickListener(this);
        binding.rlHelprlWebsite.setOnClickListener(this);
        binding.ivFeedbackListIcon.setOnClickListener(this);

/*        binding.tvHelprlWebsite.setText(BuildConfig.WEBSITE);
        binding.tvServiceTel.setText(BuildConfig.PHONE);*/

    }

    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        int id = v.getId();
        if (id == R.id.iv_helpAndFeedbackReturn) {
            Intent_utils.backIntent(this);
        } else if (id == R.id.iv_feedbackListIcon) {
            //反馈列表
            Intent_utils.enterIntent(this, FeedBackMesListActivity.class);
        } else if (id == R.id.rl_helprl_website) {
            //网站
            String url = binding.tvHelprlWebsite.getText().toString().trim();
            Log.d(TAG, "网页地址: " + url);
            //从其他浏览器打开
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            Uri content_url = Uri.parse("http://" + url);
            intent.setData(content_url);
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }
        }

    }
}
